import java.util.ArrayList;

import processing.core.*;


public class StatGenerator {
	private PApplet parent;
	private int scaleFactor = 1;
	private int currentThreshold = 1;
	public StatGenerator(PApplet parent,int scaleFactor){
		this.parent = parent;
		this.scaleFactor = scaleFactor;
	}
	
	public Float getFatalityPercentGivenForState(MapCluster state, MapCluster usa){
		return getPercentByFactors(GraphSubgroup.Fatal, null, state, usa, 4);
	}

	public ArrayList<MapCluster> getClusterByCountyGivenState(State state){
		ArrayList<MapCluster> mapClusters = new ArrayList<MapCluster>();
		MapCluster stater = new MapCluster(parent,scaleFactor,state);
		for(String county : state.counties){
			for(Integer caseNum : state.countiesToCases.get(county)){
				stater.insertCase(state.cases.get(caseNum));
			}			
		}		
		float highPer = 0;
		MapCluster newCluster = new MapCluster(parent,scaleFactor,state);
		int counter = 0;
		for(String county : state.counties){
			ArrayList<Integer> cases = state.countiesToCases.get(county);
			for(Integer c : cases){
				Case ca = state.cases.get(c);							
				newCluster.insertCase(ca);
			}
			newCluster.percent = calcFatalCrashes(newCluster,stater);
			if(highPer < newCluster.percent){
				highPer = newCluster.percent;
			}
			newCluster.setMaxPercent(highPer);
			mapClusters.add(newCluster);
			newCluster = new MapCluster(parent,scaleFactor,state);
		}		
		return mapClusters;
	}
	
	public float getPercentByFactors(GraphSubgroup group, GraphSubgroup  subgroup, MapCluster selected_cluster, MapCluster compared_cluster, int zoomLevel){
		// TODO get-her-done...
		// 4. for each subgroup, call generator for that given subgroup and groupings
		//		return an array of float, where 0<=float<=100 (for percent), 
		//		keep in mind the zoom level: 
		// 		+( 0-4 is state, 
		// 		+( 5-9 county to state
		// 		+( 10+ is individual case
		float percent = 0;
		if(group == GraphSubgroup.Fatal)
		{
			percent = calcFatalCrashes(selected_cluster, compared_cluster);
		}
		else{
			percent = calcByFactors(group,subgroup,selected_cluster,compared_cluster);
		}
		
		/*if(zoomLevel >= 0 && zoomLevel <= 4){
			
		}
		else if(zoomLevel >= 5 && zoomLevel <= 9){
			// compare against state, assume the cluster is a county
		}
		else{
			return -1;
		}*/
		return percent;
	}
	
	private float calcFatalCrashes(MapCluster selected_cluster, MapCluster compared_cluster){
		int count_selected = 0;
		int count_compared = 0;
		for(Case c : selected_cluster.Cases){
			if(c.fatalities > 0){
				count_selected++;
			}
		}
		
		for(Case c : compared_cluster.Cases){
			if(c.fatalities > 0){
				count_compared++;
			}
		}
		return (float)((float)count_selected/(float)count_compared);
	}
	
	private float calcByFactors(GraphSubgroup group, GraphSubgroup subgroup, MapCluster selected_cluster, MapCluster compared_cluster){
		// compare against the united states, assume the cluster is a state cluster
		int selected_count = 0;
		int compared_count = 0;
		switch(group){
		//--------------------------------------------Male Female -------------------------------------------
		case Male:
		case Female:
			switch(subgroup){
			case Speeding:
			case NotSpeeding:
				// fatalities of men who speed
				// fataltiies of men who don't speed
				// consolidate the subgroups
				
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Dark:
			case Dawn:
			case Dusk:
			case Daylight:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Zeroto6:
			case Sixto12:
			case Twelveto6:
			case SixtoMidnight:
			case UnknownTime:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ClearVis:
			case ObscureVis:
			case OtherVis:
			case RainVis:
			case SevereCrosswindsVis:
			case SleetHailVis:
			case SnowVis:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case HatchbackVehicle:
			case SedanVehicle:
			case OtherVehicle:
			case SUVVehicle:
			case WagonVehicle:
			case VanVehicle:
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							boolean seen = false;
							for(Person p : c.people){
								if(p.gender.equalsIgnoreCase(group.value())){
									seen = true;
									break;
								}
							}
							if(seen){
								selected_count++;
							}
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							boolean seen = false;
							for(Person p : c.people){
								if(p.gender.equalsIgnoreCase(group.value())){
									seen = true;
									break;
								}
							}
							if(seen){
								compared_count++;
							}
						}
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Alcohol:
			case NonAlcohol:
			case NotReportedAlcohol:
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value()) && p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value()) && p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ZeroTo20Age:
			case TwentyTo40Age:
			case FortyTo60Age:
			case SixtyTo80Age:
			case EightyTo100Age:
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value()) && p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value()) && p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Weekend:
			case Weekday:
				for(Case c : selected_cluster.Cases){
					if(c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}
			break;
			//-------------------------------------------Speeding Not Speeding 
		case Speeding:
		case NotSpeeding:
			switch(subgroup){
			case Male:
			case Female:
				// fatalities of men who speed
				// fataltiies of men who don't speed
				// consolidate the subgroups
				
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Dark:
			case Dawn:
			case Dusk:
			case Daylight:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						compared_count++;
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Zeroto6:
			case Sixto12:
			case Twelveto6:
			case SixtoMidnight:
			case UnknownTime:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ClearVis:
			case ObscureVis:
			case OtherVis:
			case RainVis:
			case SevereCrosswindsVis:
			case SleetHailVis:
			case SnowVis:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case HatchbackVehicle:
			case SedanVehicle:
			case OtherVehicle:
			case SUVVehicle:
			case WagonVehicle:
			case VanVehicle:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Alcohol:
			case NonAlcohol:
			case NotReportedAlcohol:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ZeroTo20Age:
			case TwentyTo40Age:
			case FortyTo60Age:
			case SixtyTo80Age:
			case EightyTo100Age:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Weekend:
			case Weekday:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.day.equalsIgnoreCase(subgroup.value())){
						selected_count++;
					}
				}				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(group.value()) && c.day.equalsIgnoreCase(subgroup.value())){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}
			break;
		case Dark:
		case Dawn:
		case Dusk:
		case Daylight:
			//---------------------------Dawn Dusk Day Dark---------------------------------------------------------
			switch(subgroup){
			case Male:
			case Female:
				// fatalities of men who speed
				// fataltiies of men who don't speed
				// consolidate the subgroups
				
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Speeding:
			case NotSpeeding:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.light.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.light.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Zeroto6:
			case Sixto12:
			case Twelveto6:
			case SixtoMidnight:
			case UnknownTime:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ClearVis:
			case ObscureVis:
			case OtherVis:
			case RainVis:
			case SevereCrosswindsVis:
			case SleetHailVis:
			case SnowVis:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case HatchbackVehicle:
			case SedanVehicle:
			case OtherVehicle:
			case SUVVehicle:
			case WagonVehicle:
			case VanVehicle:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Alcohol:
			case NonAlcohol:
			case NotReportedAlcohol:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ZeroTo20Age:
			case TwentyTo40Age:
			case FortyTo60Age:
			case SixtyTo80Age:
			case EightyTo100Age:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Weekend:
			case Weekday:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.day.equalsIgnoreCase(subgroup.value())){
						selected_count++;
					}
				}				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.day.equalsIgnoreCase(subgroup.value())){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}
			break;
			//------------------------ Hour of day-------------------------------------------------
		case Zeroto6:
		case Sixto12:
		case Twelveto6:
		case SixtoMidnight:
		case UnknownTime:
			switch(subgroup){
			case Male:
			case Female:				
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Speeding:
			case NotSpeeding:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Dawn:
			case Dark:
			case Dusk:
			case Daylight:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
				
			case ClearVis:
			case ObscureVis:
			case OtherVis:
			case RainVis:
			case SevereCrosswindsVis:
			case SleetHailVis:
			case SnowVis:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(group.value()) && c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case HatchbackVehicle:
			case SedanVehicle:
			case OtherVehicle:
			case SUVVehicle:
			case WagonVehicle:
			case VanVehicle:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Alcohol:
			case NonAlcohol:
			case NotReportedAlcohol:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ZeroTo20Age:
			case TwentyTo40Age:
			case FortyTo60Age:
			case SixtyTo80Age:
			case EightyTo100Age:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Weekend:
			case Weekday:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value()) && c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						selected_count++;
					}
				}				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(group.value()) && c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}
			break;
			//-------------------------------------atmosphere-------------------------------
		case ClearVis:
		case ObscureVis:
		case OtherVis:
		case RainVis:
		case SevereCrosswindsVis:
		case SleetHailVis:
		case SnowVis:
			switch(subgroup){
			case Male:
			case Female:				
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Speeding:
			case NotSpeeding:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Dawn:
			case Dark:
			case Dusk:
			case Daylight:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Zeroto6:
			case Sixto12:
			case Twelveto6:
			case SixtoMidnight:
			case UnknownTime:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						selected_count++;
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case HatchbackVehicle:
			case SedanVehicle:
			case OtherVehicle:
			case SUVVehicle:
			case WagonVehicle:
			case VanVehicle:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(subgroup.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Alcohol:
			case NonAlcohol:
			case NotReportedAlcohol:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ZeroTo20Age:
			case TwentyTo40Age:
			case FortyTo60Age:
			case SixtyTo80Age:
			case EightyTo100Age:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Weekend:
			case Weekday:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.day.equalsIgnoreCase(subgroup.value())){
						selected_count++;
					}
				}				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value()) && c.day.equalsIgnoreCase(subgroup.value())){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}
			break;
			// --------------------------- Vehicle -------------------------------------
		case HatchbackVehicle:
		case SedanVehicle:
		case OtherVehicle:
		case SUVVehicle:
		case WagonVehicle:
		case VanVehicle:
			switch(subgroup){
			case Male:
			case Female:				
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Speeding:
			case NotSpeeding:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							selected_count++;
						}						
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							compared_count++;
						}						
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Dawn:
			case Dark:
			case Dusk:
			case Daylight:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
							boolean seenCar = false;
							for(String car : c.vehicles){
								if(car.equalsIgnoreCase(group.value())){
									seenCar = true;
									break;
								}
							}
							if(seenCar){
								selected_count++;
							}						
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							compared_count++;
						}						
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Zeroto6:
			case Sixto12:
			case Twelveto6:
			case SixtoMidnight:
			case UnknownTime:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){							
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							selected_count++;	
						}						
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){							
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							compared_count++;	
						}						
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ClearVis:
			case ObscureVis:
			case OtherVis:
			case RainVis:
			case SevereCrosswindsVis:
			case SleetHailVis:
			case SnowVis:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(group.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenVehicle = false;
						for(String v : c.vehicles){
							if(v.equalsIgnoreCase(group.value())){
								seenVehicle = true;
								break;
							}
						}
						if(seenVehicle){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Alcohol:
			case NonAlcohol:
			case NotReportedAlcohol:
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ZeroTo20Age:
			case TwentyTo40Age:
			case FortyTo60Age:
			case SixtyTo80Age:
			case EightyTo100Age:
				for(Case c : selected_cluster.Cases){
					
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}						
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value())){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Weekend:
			case Weekday:
				for(Case c : selected_cluster.Cases){
					if(c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							selected_count++;
						}						
					}
				}				
				for(Case c : compared_cluster.Cases){
					if(c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}
			break;			
			//----------------------Alcohol----------------------
		case Alcohol:
		case NonAlcohol:
		case NotReportedAlcohol:
			switch(subgroup){
			case Male:
			case Female:				
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())&& p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value()) && p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Speeding:
			case NotSpeeding:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}						
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}			
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Dawn:
			case Dark:
			case Dusk:
			case Daylight:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}									
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}						
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Zeroto6:
			case Sixto12:
			case Twelveto6:
			case SixtoMidnight:
			case UnknownTime:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){							
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;	
						}						
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){							
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;	
						}								
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ClearVis:
			case ObscureVis:
			case OtherVis:
			case RainVis:
			case SevereCrosswindsVis:
			case SleetHailVis:
			case SnowVis:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case HatchbackVehicle:
			case SedanVehicle:
			case OtherVehicle:
			case SUVVehicle:
			case WagonVehicle:
			case VanVehicle:
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(subgroup.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(subgroup.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ZeroTo20Age:
			case TwentyTo40Age:
			case FortyTo60Age:
			case SixtyTo80Age:
			case EightyTo100Age:
				for(Case c : selected_cluster.Cases){					
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value()) && p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value()) && p.alcohol.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Weekend:
			case Weekday:
				for(Case c : selected_cluster.Cases){
					if(c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							selected_count++;
						}						
					}
				}				
				for(Case c : compared_cluster.Cases){
					if(c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(group.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}
			break;			
			//----------------------------Age------------------------------------
		case ZeroTo20Age:
		case TwentyTo40Age:
		case FortyTo60Age:
		case SixtyTo80Age:
		case EightyTo100Age:
			switch(subgroup){
			case Male:
			case Female:				
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())&& p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value()) && p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Speeding:
			case NotSpeeding:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}						
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}			
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Dawn:
			case Dark:
			case Dusk:
			case Daylight:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}									
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}						
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Zeroto6:
			case Sixto12:
			case Twelveto6:
			case SixtoMidnight:
			case UnknownTime:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){							
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;	
						}						
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){							
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;	
						}								
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ClearVis:
			case ObscureVis:
			case OtherVis:
			case RainVis:
			case SevereCrosswindsVis:
			case SleetHailVis:
			case SnowVis:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case HatchbackVehicle:
			case SedanVehicle:
			case OtherVehicle:
			case SUVVehicle:
			case WagonVehicle:
			case VanVehicle:
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(subgroup.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						boolean seenCar = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(subgroup.value())){
								seenCar = true;
								break;
							}
						}
						if(seen && seenCar){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Alcohol:
			case NonAlcohol:
			case NotReportedAlcohol:
				for(Case c : selected_cluster.Cases){					
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value()) && p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value()) && p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Weekend:
			case Weekday:
				for(Case c : selected_cluster.Cases){
					if(c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							selected_count++;
						}						
					}
				}				
				for(Case c : compared_cluster.Cases){
					if(c.day.equalsIgnoreCase(subgroup.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}			
			break;
			//--------------------------------Day---------------------------------
		case Weekend:
		case Weekday:
			switch(subgroup){
			case Male:
			case Female:				
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0 && c.day.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							selected_count++;
						}
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0 && c.day.equalsIgnoreCase(group.value())){
						boolean seen = false;						
						for(Person p : c.people){
							if(p.gender.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;					
			case Speeding:
			case NotSpeeding:
				for(Case c : selected_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;					
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.speeding.equalsIgnoreCase(subgroup.value()) && c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;		
					}					
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Dawn:
			case Dark:
			case Dusk:
			case Daylight:
				for(Case c : selected_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;
					}									
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.light.equalsIgnoreCase(subgroup.value()) && c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;					
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Zeroto6:
			case Sixto12:
			case Twelveto6:
			case SixtoMidnight:
			case UnknownTime:
				for(Case c : selected_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;					
					}
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.hour.equalsIgnoreCase(subgroup.value()) && c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;							
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ClearVis:
			case ObscureVis:
			case OtherVis:
			case RainVis:
			case SevereCrosswindsVis:
			case SleetHailVis:
			case SnowVis:
				for(Case c : selected_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						selected_count++;
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(subgroup.value()) && c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						compared_count++;
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case HatchbackVehicle:
			case SedanVehicle:
			case OtherVehicle:
			case SUVVehicle:
			case WagonVehicle:
			case VanVehicle:
				for(Case c : selected_cluster.Cases){
					if(c.fatalities > 0 && c.day.equalsIgnoreCase(group.value())){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(subgroup.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.fatalities > 0 && c.day.equalsIgnoreCase(group.value())){
						boolean seenCar = false;
						for(String car : c.vehicles){
							if(car.equalsIgnoreCase(subgroup.value())){
								seenCar = true;
								break;
							}
						}
						if(seenCar){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case Alcohol:
			case NonAlcohol:
			case NotReportedAlcohol:
				for(Case c : selected_cluster.Cases){					
					if(c.fatalities > 0 && c.day.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							selected_count++;
						}
					}					
				}
				
				for(Case c : compared_cluster.Cases){
					if(c.atmosphere.equalsIgnoreCase(group.value())){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(group.value()) && p.alcohol.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			case ZeroTo20Age:
			case TwentyTo40Age:
			case FortyTo60Age:
			case SixtyTo80Age:
			case EightyTo100Age:
				for(Case c : selected_cluster.Cases){
					if(c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							selected_count++;
						}						
					}
				}				
				for(Case c : compared_cluster.Cases){
					if(c.day.equalsIgnoreCase(group.value()) && c.fatalities > 0){
						boolean seen = false;
						for(Person p : c.people){
							if(p.age.equalsIgnoreCase(subgroup.value())){
								seen = true;
								break;
							}
						}												
						if(seen){
							compared_count++;
						}
					}
				}
				return ((float)selected_count)/((float)compared_count) * 100;
			}
			break;
			default: return 0;
		}
		return 0;

	}
	
	public void setThreshold(int thres){
		currentThreshold = thres;
	}
	
}
